/**
 * Created by qunxing.du on 2016/7/18.
 * Copyright 2016 汉威.智慧环保事业部 Limited.
 * All rights reserved.
 */
package com.hw.one.collect.zzcity.data;

import com.hw.one.collect.zzcity.analysis.HourAQIAnalysis;
import com.hw.one.collect.data.DataService;
import com.hw.one.collect.model.DataServiceType;
import com.hw.one.collect.zzcity.handler.*;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 顶层郑州市数据服务
 */
@Service
public class ZzCityDataService extends DataService {
    @Resource
    private IHandler rawDataHandler;
    @Resource
    private IHandler transformDataHandler;
    @Resource
    private IHandler analysisDataHandler;
    @Resource
    private IHandler validDataHandler;

    protected synchronized void insert(Object data, String name) throws Exception {
        HandlerChain handlerChain = new HandlerChain();
        //组合数据处理器链
        log.info("---------------name type=" + name);
        if (name.equals(DataServiceType.RAW_ONEHOUR.name()) || name.equals(DataServiceType.AUDIT_ONEHOUR.name())
                || name.equals(DataServiceType.RAW_FIVEMIN.name()) || name.equals(DataServiceType.AUDIT_FIVEMIN.name())) {
            handlerChain.add(rawDataHandler).add(validDataHandler).add(transformDataHandler).add(analysisDataHandler);
        }else {
            handlerChain.add(rawDataHandler).add(validDataHandler).add(transformDataHandler);
        }

        handlerChain.handle(data, name, handlerChain);
    }
}
